<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    #div1 {
      background-color: skyblue;
    }

    .box {
      height: 300px;
      background-color: blue;
    }
  </style>
  <script>
    window.onload = function () {
      var oDiv = document.getElementById("div1")
      // 通过.style.xxx的方式只能获取到内联的css样式
      console.log(oDiv.style.width);
      console.log(oDiv.style.backgroundColor);
      // 获取不到height
      console.log(oDiv.style.height);

      // IE兼容
      // console.log(oDiv.currentStyle["height"]);
      // 火狐、谷歌
      console.log(getComputedStyle(oDiv)["height"]);

      // 由此可写出一个跨浏览器兼容的方法
      function getStyle(node, cssStyle) {
        return node.currentStyle ? node.currentStyle[cssStyle] : getComputedStyle(node)[cssStyle];
      }
    }
  </script>
</head>

<body>
  <div id="div1" style="width: 200px;background-color: red;" class="box">111</div>
</body>

</html>